var data = {
  groupName: ['', '', ''],
  category: '',
  type: '',
  time_s: '',
  time_e: '',

  inputs: ['', '', '', '', '', ''],
  c_input: ['', '', '', ''],
  i_input: ['', '', '', ''],
  s_input: [['', '', '', '']],
  t_input: [['', '', '', '']],
  sc_input: [['', '', '', '']],

  // location: '',
  // unit: '',
  // connecter: '',
  // unit_tel: '',
  // aim: '',
  // budget: '',

  // c_name: '',
  // c_class: '',
  // c_gender: '',
  // c_phone: '',
  // i_name: '',
  // i_class: '',
  // i_gender: '',
  // i_phone: '',
  teacher: [],
  student: [],
  schedule: [],
}

Page({
  data: {
    category: { 
      name: '申报类别', change: 'category', array: [
        '', '校级团队', '院级团队'
      ]},
    type: { 
      name: '实践类型', change: 'type', array: [
        '',
        '新时代理论学习与宣讲主题实践', 
        '乡村振兴青春建功主题实践', 
        '观察浙江区域经济发展主题实践', 
        '“美丽浙江”环保主题实践', 
        '优秀传统文化宣传推广实践', 
        '“双百双进”专项', 
        '“家燕归巢”大学生回乡报到专项', 
        '反邪教宣传专项实践', 
        '其它'
    ]},
    inputs: [
      { id: 0, name: '实践具体地点' },
      { id: 1, name: '实践地接洽单位' },
      { id: 2, name: '接洽单位联系人' },
      { id: 3, name: '联系人手机号码' },
      { id: 4, name: '实践内容与目标' },
      { id: 5, name: '经费预算 (详细)' },
    ],
    array: [0, 0, 0],
    teacher: [{ id: 0, name: '', job: '', department: '', phone: '', show: 1 }],
    student: [{ id: 0, name: '', gender: '', department: '', phone: '', show: 1 }],
    schedule: [{ id: 0, location: '', detail: '', date: '', show: 1 }],
    t_detail: [
      { id: 0, name: '教师姓名' },
      { id: 1, name: '职务职称' },
      { id: 2, name: '工作部门' },
      { id: 3, name: '手机长号' },
    ], 
    s_detail: [
      { id: 0, name: '姓名' },
      { id: 1, name: '班级' },
      { id: 2, name: '性别' },
      { id: 3, name: '手机' },
    ], 
    sc_detail: [
      { id: 0, name: '活动地点' },
      { id: 1, name: '活动内容' },
    ],
    region: ['浙江省', '杭州市', '江干区'],
    date: '',
  },
  onLoad(e) {
    // this.setData({ date: formatDate(new Date()), })
  },

  groupName(e) {
    data.groupName[e.currentTarget.id] = e.detail.value;
    console.log(data)
  },
  category(e) {
    data.category = this.data.category.array[e.detail.value];
    let array = this.data.array;
    array[0] = e.detail.value;
    this.setData({ array: array });
  },
  type(e) {
    data.category = this.data.category.array[e.detail.value];
    let array = this.data.array;
    array[1] = e.detail.value;
    this.setData({ array: array });
  },
  date_s(e) {
    let string = e.detail.value.split('-')[1] + '-' + e.detail.value.split('-')[2];
    this.setData({ date_s: string });
    data.date_s = e.detail.value;
  },
  date_e(e) {
    let string = e.detail.value.split('-')[1] + '-' + e.detail.value.split('-')[2];
    this.setData({ date_e: string });
    data.date_e = e.detail.value;
  },
  inputs(e)  { data.inputs[e.currentTarget.id] = e.detail.value },
  c_input(e) { data.c_input[e.currentTarget.id] = e.detail.value },
  i_input(e) { data.i_input[e.currentTarget.id] = e.detail.value },
  s_input(e) {
    let id = e.currentTarget.id.split('-');
    data.s_input[id[0]][id[1]] = e.detail.value;
  },
  t_input(e) {
    let id = e.currentTarget.id.split('-');
    data.t_input[id[0]][id[1]] = e.detail.value;
  }, 
  sc_input(e) {
    let id = e.currentTarget.id.split('-');
    data.sc_input[id[0]][id[1]] = e.detail.value;
  },


})

function formatDate(dd) {
  var y = dd.getFullYear(), m = dd.getMonth() + 1, d = dd.getDate();
  return [y, m, d].map(formatNum).join('-');
}

function formatNum(n) {
  n = n.toString();
  return n[1] ? n : '0' + n;
}